package com.coocaa.ops.admin.v1.policygroup.convert;

import com.coocaa.ops.common.core.biz.policygroup.entity.PolicyGroupChipModelConfigEntity;
import com.coocaa.ops.common.core.biz.policygroup.entity.PolicyGroupInfoEntity;
import com.coocaa.ops.common.tool.string.StringUtil;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @author bijiahao
 * @description
 * @date 2020/3/12 15:58
 */
@UtilityClass
public class PolicyGroupSaveConverter {

    public static void handleBeforeSave(PolicyGroupInfoEntity entity) {
        if (StringUtils.isBlank(entity.getHomepageVerStart())) {
            entity.setHomepageVerStart("0000000");
        }
        if (StringUtils.isBlank(entity.getHomepageVerEnd())) {
            entity.setHomepageVerEnd("9999999");
        }
        if (null == entity.getTcVersionStart()) {
            entity.setTcVersionStart(0);
        }
        if (null == entity.getTcVersionEnd()) {
            entity.setTcVersionEnd(999999999);
        }
        entity.setMac(StringUtil.trim(entity.getMac()));

        entity.setScreenSize(StringUtil.trim(entity.getScreenSize()));

    }

    public static List<PolicyGroupChipModelConfigEntity> getFinalModelChipList(PolicyGroupInfoEntity policyGroupInfoEntity) {
        List<PolicyGroupChipModelConfigEntity> chipModelList = policyGroupInfoEntity.getRlsModelChipList();
        for (PolicyGroupChipModelConfigEntity entity : chipModelList) {
            handleTrim(entity);
            entity.setFlag(1);
            entity.setPolicyGroupId(policyGroupInfoEntity.getId());
            entity.setPolicyGroupVersion(policyGroupInfoEntity.getCurrentVersion());
            entity.setModifier(policyGroupInfoEntity.getModifier());
        }
        return chipModelList;
    }

    private static void handleTrim(PolicyGroupChipModelConfigEntity entity) {
        entity.setChip(StringUtil.trim(entity.getChip()));
        entity.setModel(StringUtil.trim(entity.getModel()));
    }

}
